import Vue from 'vue'
import VueRouter from 'vue-router'

const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)
const RouteView = {
  name: 'RouteView',
  render: (h) => h('router-view')
}

const routes = [
  // user
  {
    path: '/user',
    name: 'User',
    component: () => import('../Layout/User.vue'),
    children: [
      {
        path: '/user/login',
        name: 'Login',
        component: () => import('../views/user/login.vue')
      }
    ]
  },
  {
    path: '/',
    component: () => import('../Layout/Home.vue'),
    redirect: '/dashboard/workspace',
    children: [
      // dashboard
      {
        path: '/dashboard',
        component: RouteView,
        redirect: '/dashboard/analyze',
        children: [
          {
            path: '/dashboard/analyze',
            name: 'analyze',
            component: () => import('../views/dashbord/analyze.vue')
          },
          {
            path: '/dashboard/workspace',
            name: 'workspace',
            component: () => import('../views/dashbord/workspace.vue')
          },
          {
            path: '/dashboard/datamonitor',
            name: 'datamonitor',
            component: () => import('../views/dashbord/datamonitor.vue')
          }
        ]
      },
      // usrcenter
      {
        path: '/usrcenter',
        component: RouteView,
        redirect: '/usrcenter/usercenter',
        children: [
          {
            path: '/usrcenter/usercenter',
            name: 'usercenter',
            component: () => import('../views/usrcenter/usercenter.vue')
          },
          {
            path: '/usrcenter/usersetting',
            name: 'usersetting',
            component: () => import('../views/usrcenter/usersetting.vue')
          }
        ]
      },
      // setting
      {
        path: '/setting',
        component: RouteView,
        redirect: '/setting/userman',
        children: [
          {
            path: '/setting/userman',
            name: 'userman',
            component: () => import('../views/setting/userman.vue')
          },
          {
            path: '/setting/roleman',
            name: 'roleman',
            component: () => import('../views/setting/role.vue')
          },
          {
            path: '/setting/power',
            name: 'power',
            component: () => import('../views/setting/power.vue')
          }
        ]
      },
      // form
      {
        path: '/form',
        component: RouteView,
        redirect: '/form/basicform',
        children: [
          {
            path: '/form/basicform',
            name: 'basicform',
            component: () => import('../views/form/basicform')
          }
        ]
      }
    ]
  }
]

const router = new VueRouter({
  routes
})

export default router
